package com.scap.authen.util;

import java.io.IOException;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class DataTable {
	
	
	public @ResponseBody String springPaginationDataTables(
			HttpServletRequest request,Object voObjectList) throws IOException {

		JsonObject voJsonObject = new JsonObject();
		voJsonObject.setAaData(voObjectList);

		Gson gson = new GsonBuilder().setPrettyPrinting().create();
		String json2 = gson.toJson(voJsonObject);
		
		return json2;
	}
	
	
	public  String getDataTableLanguage(ApplicationContext context,HttpServletRequest request) {

		String vaDataTableLang = "";
		Locale voLocale = RequestContextUtils.getLocale(request);
		vaDataTableLang = context.getMessage("dataTable.sFirst", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sLast", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sNext", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sPrevious", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sLengthMenu", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sZeroRecords", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sInfo", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sEmptyTable", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sLoadingRecords", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sProcessing", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sInfoEmpty", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sInfoFiltered", null, voLocale);
		vaDataTableLang += ","+context.getMessage("dataTable.sSearch", null, voLocale);

		return vaDataTableLang;
	}

}
